<template>
    <div>
        <Modal width="820"
               v-model="modal.addTimetableFlag"
               @on-cancel="cancel"
               title="添加开课数据">
            <div class="modalDiv"></div>
            <Form ref="course" :model="course" :rules="ruleValidate" inline :label-width="100">
                <FormItem prop="worker" label="课程代码">
                    <Input class="myform" v-model="course.code" clearable/>
                </FormItem>
                <FormItem prop="collegeId" label="开课学院">
                    <Select v-model="course.collegeId" clearable class="myform">
                        <Option  v-for="item in modal.list" :value="item.collegeId" :key="item.collegeId">{{item.name}}</Option>
                    </Select>
                </FormItem>
                <FormItem prop="name" label="课程名称">
                    <Input class="myform" v-model="course.name" clearable/>
                </FormItem>
                <FormItem prop="department" label="开课系">
                    <Input class="myform" v-model="course.department" clearable/>
                </FormItem>
                <FormItem prop="grade" label="年级">
                    <Input class="myform" v-model="course.grade" clearable/>
                </FormItem>
                <FormItem prop="period" label="学时">
                    <Input class="myform" v-model="course.period" clearable/>
                </FormItem>
                <FormItem prop="point" label="学分">
                    <Input class="myform" v-model="course.point" clearable/>
                </FormItem>
                <FormItem prop="status" label="状态">
                    <Input class="myform" v-model="course.status" clearable/>
                </FormItem>
                <FormItem prop="remark" label="备注">
                    <Input class="myform" v-model="course.remark" clearable/>
                </FormItem>
            </Form>
            <Button type="primary" slot="footer" @click="ok" :loading="loading">提交</Button>
        </Modal>
    </div>
</template>

<script>
    import {AddTimetableRuleValidate} from '../ruleValidate'

    export default {
        name: "addTimetable",
        props: {
            modal: {
                addTimetableFlag: false,
                list:{}
            }
        },
        data() {
            return {
                loading: false,
                ruleValidate: AddTimetableRuleValidate(),
                course: {},
            }
        },
        methods: {
            ok() {
                this.$refs["course"].validate((valid) => {
                    if (valid) {
                        this.loading = true
                        this.http.post('/course/saveAddCourse', this.qs.parse(this.course)).then(res => {
                            if (res) {
                                this.$Message.success('添加成功！');
                                Object.assign(this.$data, this.$options.data())
                                this.modal.addTimetableFlag = false;
                                this.loading = false;
                            }
                            this.$parent.getAllTimetable();
                        })
                    } else {
                        this.$Message.error('不允许存在空值!');
                    }
                })
            },
            /**
             *选中学院之后根据学院ID去获取相关教师信息
             */



            cancel() {

            },
        },
        created() {

        }
    }
</script>

<style scoped>
    .myform {
        width: 280px;
    }
</style>